package com.imagination.applet.infrastructure.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class RestResponse<T> {

    private String code;
    private String message;

    private T data;

    public static <T> RestResponse<T> ok(T t) {
        RestResponse<T> restResponse = new RestResponse<>();
        restResponse.setCode(HttpStatus.OK.name());
        restResponse.setMessage("成功");
        restResponse.setData(t);
        return restResponse;
    }

    public static <T> RestResponse<T> ok() {
        RestResponse<T> restResponse = new RestResponse<>();
        restResponse.setCode(HttpStatus.OK.name());
        restResponse.setMessage("成功");
        return restResponse;
    }

    public static RestResponse<Void> of(String code, String message) {
        RestResponse<Void> restResponse = new RestResponse<>();
        restResponse.setCode(code);
        restResponse.setMessage(message);
        return restResponse;
    }

}
